﻿using System;
using FluentAssertions;
using NUnit.Framework;
using ReactiveGraph.Core;
using ReactiveGraph.Object.Tests;

namespace ReactiveGraph.Object.Configuration.Tests.Containers
{
    [TestFixture]
    public abstract class ContainerTestsBase
    {
        protected abstract T Resolve<T>();

        [Test]
        public void CanResolveNamedNode()
        {
            var resolveNamedNode = Resolve<Func<string, Type, IReactiveNode>>();
            var node = resolveNamedNode("Name", typeof(ReactiveNode));
            node.NodeName.Should().Be("Name");
        }

        [Test]
        public void CanResolveNodeFromType()
        {
            var resolveNamedNode = Resolve<Func<Type, IReactiveNode>>();
            var node = resolveNamedNode(typeof(ReactiveNode));
            node.Should().NotBeNull();
        }

        [Test]
        public void CanResolveNamedProperty()
        {
            var resolveNamedProperty = Resolve<Func<string, Type, IProperty>>();
            var property = resolveNamedProperty("Name", typeof(Property<string>));
            property.Name.Should().Be("Name");
        }

        [Test]
        public void CanResolveReactiveObject()
        {
            var foo = Resolve<Foo>();
            foo.Should().NotBeNull();
        }

        [Test]
        public void ResolvedObjectWillHaveName()
        {
            var foo = Resolve<Foo>();
            foo.NodeName.Should().Be("Foo1");
        }


        [Test]
        public void NodeFactoriesIsSingleTon()
        {
            Resolve<NodeFactories>().Should().BeSameAs(Resolve<NodeFactories>());
        }

        [Test]
        public void CallInitializeOnReactiveObject()
        {
            var foo = Resolve<Foo>();
            foo.FooName.Should().NotBeNull();
        }
    }
}